import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.text.JTextComponent;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

public class MainView extends JFrame {

        private JPanel contentPane, map, milestone, statistics;
        private JButton statisticsBtn, rationsAndPaceBtn, takeTurnBtn;
        private JTextArea foodArea, distArea; 
        private MilestoneModel model;
        private MapController controller;
        private StatusModel sm;
                private JButton saveBtn;
                private JTextComponent dateArea;

        /**
         * Create the frame.
         */
        public MainView(MapController controller) {
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
                setBounds(100, 100, 1215, 725);
                contentPane = new JPanel();
                MapView map = new MapView(new ImageIcon(MainView.class.getResource("northamerica.png")).getImage());
                map.setController(controller);
                MilestoneView milestone = new MilestoneView(new ImageIcon(MainView.class.getResource("vancouver.PNG")).getImage(), model, controller);
                
                MenuView menu = new MenuView();
                contentPane.setBackground(new Color(218, 165, 32));
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                getContentPane().add(map);
                map.setLocation(15, 62);
                map.setBorder(BorderFactory.createLineBorder(Color.black));
                getContentPane().add(milestone);
                milestone.setLocation(815, 422);
                milestone.setBorder(BorderFactory.createLineBorder(Color.black));
                getContentPane().add(menu);
                menu.setLocation(815, 62);
                menu.setBorder(BorderFactory.createLineBorder(Color.black));
                getContentPane().add(contentPane);
                
                
                statisticsBtn = new JButton("Check Statistics");
                statisticsBtn.setBackground(new Color(218, 165, 32));
                
                rationsAndPaceBtn = new JButton("Rations & Pace");
                rationsAndPaceBtn.setBackground(new Color(218, 165, 32));
                
                JLabel distanceLabel = new JLabel("Total Distance Traveled:");
                
                JLabel rationLabel = new JLabel("Total Food Remaining:");
                
                JLabel dateLabel = new JLabel("Date:");
                dateLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
                
                takeTurnBtn = new JButton("Take a Turn");
                takeTurnBtn.setBackground(new Color(218, 165, 32));
                
                saveBtn = new JButton("Save Game");
                saveBtn.setBackground(new Color(218, 165, 32));
                
                foodArea = new JTextArea();
                foodArea.setEditable(false);
                
                distArea = new JTextArea();
                distArea.setEditable(false);
                
                dateArea = new JTextArea();
                dateArea.setEditable(false);
                
                GroupLayout gl_contentPane = new GroupLayout(contentPane);
                gl_contentPane.setHorizontalGroup(
                        gl_contentPane.createSequentialGroup()
                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addComponent(distanceLabel)
                                                        .addPreferredGap(ComponentPlacement.RELATED)
                                                        .addComponent(distArea, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
                                                 )
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGap(5)
                                                        .addComponent(rationLabel)
                                                        .addPreferredGap(ComponentPlacement.UNRELATED)
                                                        .addComponent(foodArea, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
                                                 )
                                          )
                                          .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                                .addGap(25)
                                                        .addComponent(dateLabel)
                                                        .addPreferredGap(ComponentPlacement.RELATED)
                                                        .addComponent(dateArea, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                                                        .addGap(490)
                                                        .addComponent(saveBtn)
                                                        .addComponent(takeTurnBtn)
                                                 )
                                                
                                          )                 
                );
       
                gl_contentPane.setVerticalGroup(
                        gl_contentPane.createParallelGroup(Alignment.LEADING)
                                .addGroup(gl_contentPane.createSequentialGroup()
                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                                                .addComponent(distanceLabel)
                                                                .addComponent(distArea, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
                                                                 )
                                                        .addPreferredGap(ComponentPlacement.RELATED)
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                                                .addComponent(rationLabel)
                                                                .addComponent(foodArea, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(dateLabel)
                                                                .addComponent(dateArea, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(saveBtn)
                                                                .addComponent(takeTurnBtn))
                                                                 )
                                                          )
                    
                                                 )
                );
                contentPane.setLayout(gl_contentPane);
        }
        
        public JButton getTakeTurnBtn()
        {
                return takeTurnBtn;
        }
        
        public JButton getSaveBtn()
        {
                return saveBtn;
        }
        
        public JButton getRationsAndPaceBtn()
        {
                return rationsAndPaceBtn;
        }
        
        public void setDistArea(int dist)
        {
                distArea.setText("" + dist);
        }
        
        public void setFoodLbs(int lbs)
        {
                foodArea.setText("" + lbs);
        }
        
        public void addBtnListener(ActionListener al)
        {
                takeTurnBtn.addActionListener(al);
                rationsAndPaceBtn.addActionListener(al);
                saveBtn.addActionListener(al);
        }
}